define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'fixed_cate/index' + location.search,
                    add_url: 'fixed_cate/add',
                    edit_url: 'fixed_cate/edit',
                    del_url: 'fixed_cate/del',
                    multi_url: 'fixed_cate/multi',
                    import_url: 'fixed_cate/import',
                    table: 'fixed_cate',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'coverimage', title: __('Coverimage'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'backimage', title: __('内页背景图'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'buttons', title: __('Operate'), table: table, events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'fixed_cate_goods',
                                    text: __('相关商品'),
                                    title: __('相关商品'),
                                    classname: 'btn btn-xs btn-info btn-dialog',
                                    url: 'fixed_cate_goods/index?cate_id={ids}',
                                    extend: 'data-toggle="tooltip" data-area=\'["100%", "100%"]\'',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                },
                                {
                                    name: 'edit',
                                    text: ' ',
                                    title: __('编辑'),
                                    classname: 'btn btn-xs btn-success btn-editone',
                                    icon: 'fa fa-pencil',
                                    url: 'fixed_cate/edit/ids/{ids}',
                                    extend: 'data-toggle="tooltip"',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    },
                                    visible: function (row) {
                                        //返回true时按钮显示,返回false隐藏
                                        return true;
                                    }
                                }
                            ],
                            formatter: Table.api.formatter.buttons
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});